import Vue from 'vue'
import VueRouter from 'vue-router'
import Detail from '../views/detail/index.vue'
import Footer from '../components/footer.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/home/index.vue'),
      footer: Footer
    }
  }, {
    path: '/kind',
    name: 'Kind',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/kind/index.vue'),
      footer: Footer
    }
  }, {
    path: '/cart',
    name: 'Cart',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/cart/index.vue'),
      footer: Footer
    }
  },
  {
    path: '/my',
    name: 'My',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/my/index.vue'),
      footer: Footer
    }
  },
  {
    path: '/detail/:id',
    name: 'detail',
    component: Detail
  },
  {
    path: '/register',
    name: 'register',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/register/index.vue')
    }
  }
]
// 动态路由传递数据的方式
// params
// 路由的定义格式：path: '/detail/:id'
// 路由的跳转格式：/detail/jagduy1uy1f
// http://localhost:8080/detail/pro44172272-0ead-11eb-8223-5d4b2a238f09
// 解析：$router.params.id
// query
// 路由的定义格式：path: '/detail'
// 路由的跳转格式：/detail?id=jagduy1uy1f
// http://localhost:8080/detail/?id=pro44172273-0ead-11eb-8223-5d4b2a238f09
// 解析：$router.query.id
// 路由的跳转方式
// 标签跳转：router-link
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
